package org.stvd.repository.common.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.stvd.entities.common.AffixInfo;
import org.stvd.repository.base.impl.BaseDaoImpl;
import org.stvd.repository.common.AffixInfoDao;

/**
 * 附件映射Repository实现类
 * @author houzx
 */
@Repository("AffixInfoDao")
public class AffixInfoDaoImpl extends BaseDaoImpl<AffixInfo> implements AffixInfoDao{

    @Override
    public List<AffixInfo> listAffixInfo(String infoType, String infoTable, String infoId) {
        String hql = "FROM AffixInfo WHERE checkStatus != '-1'"
            + " AND (infoType = ?0 OR '' = ?0)"
            + " AND (infoTable = ?1 OR '' = ?1)"
            + " AND (infoId = ?2 OR '' = ?2)";
        return findByHQL(hql, infoType, infoTable, infoId);
    }
    
    @Override
    @Transactional
    public int deleteAffixInfo(String infoType, String infoTable, String infoId) {
        String hql = "UPDATE AffixInfo SET checkStatus = '-1'"
            + " WHERE (infoType = :infoType OR '' = :infoType)"
            + " AND (infoTable = :infoTable OR '' = :infoTable)"
            + " AND (infoId = :infoId OR '' = :infoId)";
        return em.createQuery(hql)
            .setParameter("infoType", infoType)
            .setParameter("infoTable", infoTable)
            .setParameter("infoId", infoId)
            .executeUpdate();
    }

}
